package com.zyb.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zyb.mapper.ClazzMapper;
import com.zyb.pojo.Clazz;
import com.zyb.service.ClazzService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class ClazzServiceImpl extends ServiceImpl<ClazzMapper, Clazz> implements ClazzService {

    @Override
    public IPage<Clazz> getClazzPage(Integer pageNo, Integer pageSize, Clazz clazz) {
        IPage<Clazz> clazzIPage=new Page<>(pageNo,pageSize);
        String name = clazz.getName();
        String gradeName = clazz.getGradeName();

        QueryWrapper<Clazz> wrapper=new QueryWrapper<>();
        if (!StringUtils.isEmpty(gradeName)){
            wrapper.like("grade_name",gradeName);
        }
        if (!StringUtils.isEmpty(name)){
            wrapper.like("name",name);
        }
        wrapper.orderByDesc("id");
        IPage<Clazz> iPage = baseMapper.selectPage(clazzIPage, wrapper);
        return iPage;
    }

    @Override
    public List<Clazz> getClazzs() {
        return baseMapper.selectList(null);
    }
}
